<template>
	<uv-modal ref="orderConfirmModal" title="确认接单" cancelColor="#006BFE" :showCancelButton="true" cancelText="取消"
		confirmText="确认" :asyncClose="true" @confirm="handleConfirmOder" @cancel="onCancel">
		<uv-cell-group>
			<uv-cell title="约定作业时间" :isLink="true" :border="false" :value="time" @click="handleClick"></uv-cell>
		</uv-cell-group>
		<uv-datetime-picker ref="datetimePicker" :minDate="minDate" :maxDate="1786778555000" v-model="dateValue"
			mode="datetime" @confirm="confirmTime">
		</uv-datetime-picker>
	</uv-modal>
</template>

<script>
	export default {
		data() {
			return {
				minDate: Date.now(),
				id: '',
				time: '',
				dateValue: Number(new Date()),
			}
		},
		methods: {
			show(data) {
				this.id = data.id
				this.time = data.dockingPeopleTime
				this.dateValue = Date.now()
				this.$refs.orderConfirmModal.open();
			},
			handleClick() {
				this.$refs.datetimePicker.open();
			},
			confirmTime(e) {
				this.time = uni.$uv.timeFormat(e.value, 'yyyy-mm-dd hh:MM:ss')
			},
			onCancel() {
				this.$refs.orderConfirmModal.closeLoading()
				this.$refs.orderConfirmModal.close();
				// this.$http.post(`/cadre/assignOrder/cancelOrder`,{}, {
				// 	params: {
				// 		orderId: this.id,
				// 		timeout: 2
				// 	}
				// }).then(res => {
				// 	uni.showToast({
				// 		title:res.msg
				// 	})
				// 	this.$emit('success')
				// 	this.$refs.orderConfirmModal.closeLoading()
				// 	this.$refs.orderConfirmModal.close();
				// })
			},
			handleConfirmOder() {
				this.$http.post(`/cadre/assignOrder/confirm`, {}, {
					params: {
						orderId: this.id,
						dockingPeopleTime: this.time
					}
				}).then(res => {
					if (res.code === 200) {
						this.$emit('success')
						this.$refs.orderConfirmModal.closeLoading()
						this.$refs.orderConfirmModal.close();
					} else if (res.code === 500) {
						this.$refs.orderConfirmModal.closeLoading()
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					} else {
						this.$refs.orderConfirmModal.closeLoading()
						uni.showToast({
							title: res.msg || '操作失败',
							icon: 'none'
						});
					}
				})
			}
		},
	}
</script>

<style>
</style>